<?php
namespace core\lib;

class conf
{
    public static $conf = array();

    public static function get($name, $file)
    {
        /**
         * 1.判断配置文件是否存在
         * 2.判断配置是否存在
         * 3.缓存配置
         */

        if (isset(self::$conf[$file])) {
            return self::$conf[$file][$name];
        } else {
            $filePath = MPHP . '/core/config/' . $file. '.php';
            if (is_file($filePath)) {
                $confData = include $filePath;
                if (isset($confData[$name])) {
                    self::$conf[$file] = $confData;
                    return $confData[$name];
                } else {
                    throw new \Exception('没有这个配置项' . $name);
                }
            } else {
                throw new \Exception('找不到配置文件' . $file);
            }
        }
    }

    public static function all($file)
    {
        if (isset(self::$conf[$file])) {
            return self::$conf[$file];
        } else {
            $filePath = MPHP . '/core/config/' . $file. '.php';
            if (is_file($filePath)) {
                $confData = include $filePath;
                    self::$conf[$file] = $confData;
                    return $confData;
            } else {
                throw new \Exception('找不到配置文件' . $file);
            }
        }
    }

}